#ifndef _SEMAPHORES_H_
#define _SEMAPHORES_H_

#include "types.h"
#include "err.h"

typedef enum
{
	SEM_UNLOCKED,	//value must be 0/1.
	SEM_LOCKED
}sem_state_t;

typedef enum
{
  SEM_LOCAL,
  SEM_SHARED
}sem_opt_t;

typedef struct process_list_t
{
	struct process_list_t *next_process;
	struct process_list_t *prev_process;
}process_list_t;

typedef struct 
{
	sem_state_t sem_lock;
	process_list_t process_list;
	sem_opt_t sem_opt;
	err_t err_code;
}sem_t;

typedef struct
{
  sem_t *sem_ptr;
	bool lock_successful;
	err_t err_code;
}sem_trylock_t;


err_t sem_create(sem_t **);
err_t sem_create_shared(sem_t **);
err_t sem_create_blocked(sem_t **sem_pp);
err_t sem_lock(sem_t * sem_ptr);
err_t sem_unlock(sem_t *sem_ptr);
err_t sem_trylock(sem_t *sem_ptr);
err_t sem_release(sem_t *sem_ptr);
err_t sem_create2(sem_t *sem_p, bool shared, bool blocked);

#endif
